<template>
	<joy-page class="">
		<uni-card title="科目">
			<uni-grid :gridList="kemu" show-border="false" @click="getTeacherList" :activeIndex='curKm' columnNum="4"></uni-grid>
		</uni-card>
		<uni-card title="教师">
			<uni-grid :gridList="teacher" show-border="false" @click="getShiTiList" :activeIndex='curTea' columnNum="4"></uni-grid>
		</uni-card>
		<uni-card title="试题" extra="更多" @extraClick="goShiTiMore">
			<view class="uni-list">
				<view class="uni-list-cell" hover-class="uni-list-cell-hover" v-for="(item, index) in st" :key="index" @click="goShitiDetail(item.questionsid)">
					<view class="uni-media-list">
						<view class="uni-media-list-body">
							<view class="uni-media-list-text-top">
								<text style="">{{ item.questionsname }}</text>
							</view>
						</view>
						<!-- <text class="cell-more yticon icon-you"></text> -->
					</view>
				</view>
			</view>
		</uni-card>
	</joy-page>
</template>

<script>
	import uniGrid from "@/components/uni-grid/uni-grid.vue"
	import uniCard from "@/components/uni-card/uni-card.vue"
	import mPageView from "@/components/m-page-view/m-page-view.vue"
	import subjectiveCaseApi from "@/api/subjectiveCase.js"
	let _this;
	export default {
		components: {
			uniGrid,
			uniCard,
			"joy-page": mPageView
		},

		data() {
			return {
				banner: [],
				grid: [],
				adList: [],
				st: [],
				teacher: [],
				kemu: [],
				curKm: '',
				curTea: '',


			}
		},
		onPullDownRefresh() {
			console.log('refresh');
			_this.curKm= ''
			_this.curTea= ''
			_this.initData()
		},
		onLoad(query) {
			_this = this
			_this.initData()
		},
		onNavigationBarButtonTap(object){
			console.log(object)
			let teacode = ''
			console.log(teacode)
			//跳转到个人答题页面
			uni.navigateTo({
				url:`/pages/subjectiveCase/user-answer?teacode=${teacode}`
			})
			
		},
		computed: {
		},
		methods: {
			initData() {
				subjectiveCaseApi.zgal().then(res => {
					console.log(res)
					_this.kemu = res.data.km || [];
					_this.kemu.forEach((item, index) => {
						item.id=item.type,
						item.text= item.name,
						item.image= item.content
					})
					_this.teacher = res.data.tea || [];
					_this.teacher.forEach((item, index) => {
						item.id= item.usercode
						item.text= item.userxm
						item.image= item.picture
					})
					
					_this.st = res.data.st || [];
					if (_this.kemu.length > 0) {
						_this.curKm = _this.kemu[0].type
					}
					if (_this.teacher.length > 0) {
						_this.curTea = _this.teacher[0].usercode
					}
					uni.stopPullDownRefresh();
				}).catch(err => {
					uni.stopPullDownRefresh();
				})
			},
			getTeacherList(id) {
				_this.curKm = id
				subjectiveCaseApi.l_teacher({
					id: id
				}).then(res => {
					console.log(res)
					_this.curTea = ''
					_this.teacher = res.data || []
					_this.teacher.forEach((item, index) => {
						item.id= item.usercode
						item.text= item.userxm
						item.image= item.picture
					})
					_this.st = []
					if (_this.teacher.length == 0) {
						return
					}
					let teacher = _this.teacher[0]
					
					_this.getShiTiList(teacher.usercode)

				})
			},
			getShiTiList(id) {
				_this.curTea = id
				subjectiveCaseApi.l_que_list_by_tea({
					id: id
				}).then(res => {
					console.log(res)
					res.data = res.data || [];
					_this.st = res.data
				})
			},
			goShiTiMore() {
				let id = _this.curTea
				console.log(_this.curTea)
				if (id == '') {
					return
				}
				uni.navigateTo({
					url: `/pages/subjectiveCase/list?id=${id}`
				})
			},
			goShitiDetail(id) {
				console.log(id)
				uni.navigateTo({
					url: `/pages/subjectiveCase/detail?id=${id}&teacode=${_this.curTea}`
				})
			},

		}
	}
</script>

<style lang="scss" scoped>
	@import url("../../common/uni/uni.css");

	body,
	page {
		min-height: 100%;
		display: flex;
		font-size: 32upx;
	}

	body.modal-open {
		position: fixed;
		width: 100%;
	}

	.ad-box {
		display: flex;
		justify-content: center;
		background: #fff;

		/* margin-top: 10upx; */
		.ad {
			image {

				width: 335upx;
				height: 185upx;
				margin: 15upx;
			}
		}
	}

	/* #ifdef MP-BAIDU */
	page {
		width: 100%;
		height: 100%;
		display: block;
	}



	swan-template {
		width: 100%;
		min-height: 100%;
		display: flex;
	}

	/* #endif */

	.content {
		display: flex;
		flex: 1;
		flex-direction: column;
		background-color: #efeff4;
		width: 100%;
	}

	.pad-10 {
		padding: 10upx;
	}

	.mt-10 {
		margin-top: 10upx;
	}

	.ellipsis {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.input-row {
		display: flex;
		flex-direction: row;
		position: relative;
		background: #fff;
	}

	.input-row .title {
		width: 25%;
		padding: 20upx 0;
		padding-left: 20upx;
		line-height: 50upx;
	}

	.border-1px {
		position: relative;

		&::before {
			position: absolute;
			z-index: 1;
			right: 0;
			top: 0;
			left: 0upx;
			height: 1upx;
			content: '';
			-webkit-transform: scaleY(.5);
			transform: scaleY(.5);
			background-color: #e2e2e2;
		}

		&::after {
			position: absolute;
			z-index: 1;
			right: 0;
			bottom: 0;
			left: 0upx;
			height: 1upx;
			content: '';
			-webkit-transform: scaleY(.5);
			transform: scaleY(.5);
			background-color: #e2e2e2;
		}
	}

	.border-bottom-1px {
		position: relative;

		&::after {
			position: absolute;
			z-index: 1;
			right: 0;
			bottom: 0;
			left: 20upx;
			height: 1upx;
			content: '';
			-webkit-transform: scaleY(.5);
			transform: scaleY(.5);
			background-color: #e2e2e2;
		}
	}

	.btn-row {
		margin-top: 50upx;
		padding: 20upx;
	}

	button.primary {
		background-color: #0faeff;
	}

	.ka {
		width: 100%;
		height: 260upx;
		position: relative;

		&:after {
			content: '';
			position: absolute;
			transform-origin: center;
			box-sizing: border-box;
			pointer-events: none;
			top: -50%;
			left: -50%;
			right: -50%;
			bottom: -50%;
			border-bottom: 1px solid $uni-border-color;
			transform: scale(.5);
		}
	}


	.uni-media-list {
		padding: 10px 10px;
	}

	.uni-media-list-logo {
		width: 220upx;
		height: 160upx;
	}

	.uni-media-list-body {
		height: auto;
		justify-content: space-around;
	}

	.uni-media-list-text-top {
		// height: 60upx;
		font-size: 28upx;

	}
	// .uni-media-list-text-top>text{
	// 	width: 90%;
	// 	display: -webkit-box;
	//    -webkit-box-orient: vertical;
	//    -webkit-line-clamp: 1;
	//    overflow: hidden;
	// }
	.uni-media-list-text-body {
		// height: 60upx;
		font-size: 28upx;

	}

	.uni-media-list-text-bottom {
		// height: 60upx;
		font-size: 28upx;

	}

	.uni-list::before,
	.uni-list:after {
		height: 0px;
	}
</style>
